<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>团队奖励规则</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        
        <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">

        <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
  	    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
        
        <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
        <script type="text/javascript" src="/static/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
    </head>
<body style="background-color: #FFF;">
    <div style="padding: 20px">
        <table class="layui-hide" id="test" lay-filter="test"></table>
    </div>

    <script>
        layui.use('table', function(){
            var table = layui.table;

            function getList(){
                table.render({
                    elem: '#test'
                    ,url:'{:url("Reward/team_data")}'
                    ,toolbar: true // 开启头部工具栏
                    ,defaultToolbar: true
                    ,cols: [[
                        {field:'push_number', title:'直推人数', edit: 'text'}
                        ,{field:'sales', title:'进货量', edit: 'text'}
                        ,{field:'reward', title:'奖励', edit: 'text'}
                    ]]
                });
            }

            getList()

            // 监听单元格编辑
            table.on('edit(test)', function(obj){ //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
                // console.log(obj.value); //得到修改后的值
                // console.log(obj.field); //当前编辑的字段名
                // console.log(obj.data); //所在行的所有相关数据

                $.post('{:url("Reward/team_edit")}',{
                    id: obj.data.id
                    ,field: obj.field
                    ,value: obj.value
                },function(res){
                    if(res.code == 400){
                        layer.msg(res.msg, {icon: 2});
                        setTimeout(() => {
                            window.location.reload()
                        }, 1000);
                    }else{
                        layer.msg(res.msg, {icon: 1});
                    }
                })
            });
        });
    </script>
</body>
</html>